package com.frank.millen;

import org.apache.wicket.markup.html.form.CheckBox;
import org.apache.wicket.markup.html.form.PasswordTextField;
import org.apache.wicket.markup.html.form.StatelessForm;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;

import com.frank.millen.common.AbstractBasePage;

public class SignInPage extends AbstractBasePage {

	private static class SignInForm extends StatelessForm {

		private String password;
		private String username;
		private Boolean remember;

		public SignInForm(final String id) {
			super(id);
			setModel(new CompoundPropertyModel(this));
			add(new TextField("username"));
			add(new PasswordTextField("password"));
			add(new CheckBox("remember"));
		}

		@Override
		public final void onSubmit() {
			if (signIn(username, password)) {
				if (!continueToOriginalDestination()) {
					setResponsePage(RegisterPage.class);
				}
			} else {
				error("Das von ihnen eingegebene Passwort ist falsch. Bitte geben sie ihren Daten erneut ein.");
			}
		}

		public boolean signIn(String username, String password) {
			if (username != null && password != null) {
				return true;
				/*
				 if ( DataBase.getInstance().checkLogin(username, password)) {
				 milSession.get().setUser(user); return true; 
				 }		
				 */
			}		
		return false;
		}

	}

	public SignInPage() {

		add(new SignInForm("signInForm"));
		add(new FeedbackPanel("feedback"));
	}
}
